/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rcnss.application.configuration;

import com.rcnss.application.tool.XMLTools;
import java.io.IOException;

/**
 *
 * @author Baligh GUESMI
 */
public class Configuration {

    private String DataBaseServerIP;
    private String DataBaseUsername;
    private String DataBasePassword;
    private String DataBaseServerPort;

    public Configuration() {
        
    }

    public Configuration(String DataBaseServerIP,String DataBaseServerPort,
            String DataBaseUsername, String DataBasePassword) {
        this.DataBasePassword = DataBasePassword;
        this.DataBaseServerIP = DataBaseServerIP;
        this.DataBaseServerPort= DataBaseServerPort;
        this.DataBaseUsername = DataBaseUsername;
    }

    public String getDataBaseServerIP() {
        return this.DataBaseServerIP;
    }

    public String getDataBaseServerPort() {
        return this.DataBaseServerPort;
    }

    public String getDataBaseUsername() {
        return this.DataBaseUsername;
    }
    
    public String getDataBasePassword() {
        return this.DataBasePassword;
    }

    public void setDataBaseServerIP(String DataBaseServerIP) {
        this.DataBaseServerIP = DataBaseServerIP;
    }

    public void setDataBaseServerPort(String DataBaseServerPort) {
        this.DataBaseServerPort = DataBaseServerPort;
    }

    public void setDataBaseUsername(String DataBaseUsername) {
        this.DataBaseUsername = DataBaseUsername;
    }

    public void setDataBasePassword(String DataBasePassword) {
        this.DataBasePassword = DataBasePassword;
    }

    public boolean  saveToXML()
    {
        try {
            XMLTools.encodeToFile(this, "Conf.xml");
        } catch(Exception e) {
            return false;
        }
        return true;
    }

    public boolean loadFromXML()
    {
        Configuration c = new Configuration("","","","");
        boolean rv = true;
        try {
            c = (Configuration)XMLTools.decodeFromFile("Conf.xml");
        } catch (IOException ex) {
            rv = false;
        }
        this.DataBasePassword = c.getDataBasePassword();
        this.DataBaseServerIP = c.getDataBaseServerIP();
        this.DataBaseServerPort= c.getDataBaseServerPort();
        this.DataBaseUsername = c.getDataBaseUsername();
        return rv;
    }

    @Override
    public String toString() {
        return "";
    }

}
